package com.beiyou.orderingsystemonweb.shop.controller;

import com.beiyou.orderingsystemonweb.shop.service.ShopFoodService;
import com.beiyou.orderingsystemonweb.system.controller.UtilController;
import com.beiyou.orderingsystemonweb.util.HomeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RequestMapping("/shopFood")
@Controller
public class ShopFoodController {
    //文件上传--我之前已经保存了，这里就没有写文件保存

    @Autowired
    ShopFoodService shopFoodService;
    @RequestMapping("/addShopFood.do")
    public String add(String fileImg ,String foodId,HttpServletRequest request, HttpSession session, String foodPrice, String foodName, MultipartFile foodImg){
        String shopId = session.getAttribute("shopId").toString();
        UtilController utilController = new UtilController();
        Map map = utilController.filePost(foodImg, fileImg);

        //可能是更新菜品
        if (foodId!=null){
            shopFoodService.updateShopFood(foodId,foodName, map.get("filename").toString(),foodPrice);
        }
        else{
            shopFoodService.addShopFood(shopId,foodName, map.get("filename").toString(),foodPrice);

        }

        return "redirect:/shop/shopHome.do";
    }



}
